package com.yoomiito.app.ui.my;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yoomiito.app.Constant;
import com.yoomiito.app.R;
import com.yoomiito.app.base.App;
import com.yoomiito.app.model.bean.TabBean;
import com.yoomiito.app.present.my.activity.MyInvitePresenter;
import com.yoomiito.app.share.ui.InviteShareActivity;
import com.yoomiito.app.share.ui.NewInviteShareActivity;
import com.yoomiito.app.ui.fragment.my.MyInviteFragment;
import com.yoomiito.app.ui.fragment.my.MyOrderBaseFragment;
import com.yoomiito.app.ui.fragment.my.MyVipFragment;
import com.yoomiito.app.utils.AllCode;
import com.yoomiito.app.utils.EventMessage;
import com.yoomiito.app.utils.ResUtil;
import com.yoomiito.app.utils.UserInfoConfig;
import com.yoomiito.app.widget.dialog.SelectDialog;
import com.yoomiito.app.widget.wheelview.DateSelectDialog;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的邀请
 */
public class MyInviteActivity extends MyOrderBaseActivity<MyInvitePresenter> {
    public final static String KEY_INVITE_NUM = "key_invite_num";
    SelectDialog dialog;
    MyInviteFragment vipFm;
    MyInviteFragment sddFm;
    MyInviteFragment normalFm;

    @Override
    public MyInvitePresenter newP() {
        return new MyInvitePresenter(App.mAppConfig);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        int num = getIntent().getIntExtra(KEY_INVITE_NUM, 0);
        desTitleTv.setVisibility(View.GONE);
        titleView.setCenterText("我的用户");
        titleView.setRightTv(ResUtil.getString(R.string.my_invite_people));
        titleView.setOnRightClick(view -> {
            NewInviteShareActivity.start(MyInviteActivity.this, AllCode.InviteFriend);
        });
        topLayout.setBackground(ResUtil.getDrawable(R.mipmap.remain_bg));
        moneyTv.setText("" + num);
        desTv.setText("邀请总数");
        ImageView ivSelect = findViewById(R.id.iv_select);
        ivSelect.setVisibility(View.VISIBLE);
        ivSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (dialog == null)
                    dialog = new SelectDialog(MyInviteActivity.this);
                dialog.setOnResultListener(new SelectDialog.OnResultListener() {
                    @Override
                    public void onResult(String time, String name) {
                        if(vipFm!=null)
                            vipFm.setData(name,time);
                        if(sddFm!=null)
                            sddFm.setData(name,time);
                        if(normalFm!=null)
                            normalFm.setData(name,time);
                        EventMessage eventMessage = new EventMessage();
                        eventMessage.setEventType("invite");
                        eventMessage.setMsg(time);
                        eventMessage.setGoodsID(name);
                        EventBus.getDefault().post(eventMessage);

                    }
                });
                dialog.show();
            }
        });
    }


    public void setTotal(String num) {
        moneyTv.setText("" + num);
    }


    @Override
    protected List<MyOrderBaseFragment> getAllFragment() {
        List<MyOrderBaseFragment> list = new ArrayList<>();
        normalFm = new MyInviteFragment();
        Bundle normalBundle = new Bundle();
        normalBundle.putInt(MyVipFragment.KEY_TYPE, Constant.USER_TYPE_NORMAL);
        normalFm.setArguments(normalBundle);

        vipFm = new MyInviteFragment();
        Bundle vipBundle = new Bundle();
        vipBundle.putInt(MyVipFragment.KEY_TYPE, Constant.USER_TYPE_VIP);
        vipFm.setArguments(vipBundle);

        sddFm = new MyInviteFragment();
        Bundle sddBundle = new Bundle();
        sddBundle.putInt(MyVipFragment.KEY_TYPE, Constant.USER_TYPE_SDD_VIP);
        sddFm.setArguments(sddBundle);

        list.add(normalFm);
        list.add(vipFm);
        list.add(sddFm);
        return list;
    }

    @Override
    protected List<TabBean> getTabList() {
        List<TabBean> tabs = new ArrayList<>();
        tabs.add(new TabBean(ResUtil.getString(R.string.my_user_normal), 0, true));
        tabs.add(new TabBean(ResUtil.getString(R.string.my_user_vip), 0, true));
        tabs.add(new TabBean("我的", 0, true));

        return tabs;
    }
}
